﻿<%@ page pageEncoding="UTF-8"%>
<%@include file="/util/tag.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <%@include file="../common/head.jsp"%>

        <script language="javascript" type="text/javascript">
            //保存成功的提示信息
            function showResult() {
                showResultDiv(true);
                window.setTimeout("showResultDiv(false);", 3000);
            }
            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }

          		
            function searchAccounts() {
   								 var b = false;
                $.ajax({
									    'url':"../account/findByIdcard",
									    'dataType':'json',
									    'data':{idcardNo:$("#idcardNo").val()},
									    'async':false,
									    'success':function(data){
									    				b=data.ok;
									        	if(data.ok){
									        			//alert(data.loginName+","+data.id);
									        			$("#loginName").val(data.loginName);
									        			$("#accountId").val(data.id);
									        			$("#idcard_msg").removeClass("error_msg").empty();
									        		}else{
									        			$("#idcard_msg").addClass("error_msg").empty().text("没有此身份证号，请重新录入。");
									        		}
									        	}
										});
										return b;
            }
            jQuery.validator.addMethod("searchAccounts",searchAccounts);            
$(function(){
	
	$("#serviceForm").validate({
		rules:{
			"idcardNo":{required:true},
			"loginName":{required:true,remote:"../account/validName?"+$(this).serialize()},
			"ser.unixHost":{required:true,remote:"verifyHost?"+$(this).serialize()},
			"ser.osUsername":"required",
			"ser.loginPassword":"required",
			"confirm_pwd":{required:true,equalTo:"#loginPassword"}
		},
		messages:{
			"idcardNo":{required:"请填写身份证号"},
			"loginName":{required:" 请填写账务账号",remote:"没有此账务账号，请重新录入。"},
			"ser.unixHost":{required:"请填写IP",remote:"没有此服务器，请重新录入。"},
			"ser.osUsername":"请填写登录账号",
			"ser.loginPassword":"请填写密码",
			"confirm_pwd":{required:"请填写重复密码",equalTo:"两次密码必须相同"}
		},errorPlacement:function(error,element) {
       error.appendTo($(element).siblings(":last").addClass("error_msg").empty());
   },success:function(label,element){
       $(element).siblings(":last").removeClass("error_msg").empty();
       	}
	});
	$("#save").click(function(){
		if($("#serviceForm").valid()){
			var b=$("#serviceForm").submitForm("save",
            			"保存失败！"+$("#unixHost").val()+"服务器上已经开通过 OS 账号 "+$("#username").val()+"。",
            			'保存成功!',$("#save_result_info"));
            			if(b){
            				$('#save_result_info').attr("class","save_success");
            			}else{
            				$('#save_result_info').attr("class","save_fail");
            			}
            			showResult();
		}
	});
});
        	

        </script>
    <body>
           
        <%@include file="../common/top.jsp"%>
	 
        <!--主要区域开始-->
        <div id="main">
            <!--保存操作的提示信息-->
            <div id="save_result_info" class="save_fail">保存失败！192.168.0.23服务器上已经开通过 OS 账号 “mary”。</div>
            <form action="#" method="get" class="main_form" id="serviceForm">
                <!--内容项-->
                <div class="text_info clearfix"><span>身份证：</span></div>
                <div class="input_info">
                    <input type="text" id="idcardNo" name="idcardNo"class="width180" />
                    <input type="button" value="查询账务账号" class="btn_search_large" 
                    onclick="searchAccounts();"/>
                    <span class="required">*</span>
                    <div class="validate_msg_short" id="idcard_msg"></div>
                </div>
                <div class="text_info clearfix"><span>账务账号：</span></div>
                <div class="input_info">
                    <input type="hidden" name="ser.account.id" id="accountId"/>
                    <input type="text" id="loginName" name="loginName"/>
                    <span class="required">*</span>
                    <div class="validate_msg_long"></div>
                </div>
                <div class="text_info clearfix"><span>资费类型：</span></div>
                <div class="input_info">
                    <select name="ser.cost.id">
                       <s:iterator value="costList">
                       	<option value="${id}">${name}</option>
                       </s:iterator>
                    </select>                        
                </div> 
                <div class="text_info clearfix"><span>服务器 IP：</span></div>
                <div class="input_info">
                    <input type="text" name="ser.unixHost"  id="unixHost"/>
                    <span class="required">*</span>
                    <div class="validate_msg_long"></div>
                </div>                   
                <div class="text_info clearfix"><span>登录 OS 账号：</span></div>
                <div class="input_info">
                    <input type="text" name="ser.osUsername" id="username" />
                    <span class="required">*</span>
                    <div class="validate_msg_long"></div>
                </div>
                <div class="text_info clearfix"><span>密码：</span></div>
                <div class="input_info">
                    <input type="password" id="loginPassword" name="ser.loginPassword"/>
                    <span class="required">*</span>
                    <div class="validate_msg_long"></div>
                </div>
                <div class="text_info clearfix"><span>重复密码：</span></div>
                <div class="input_info">
                    <input type="password" name="confirm_pwd" />
                    <span class="required">*</span>
                    <div class="validate_msg_long"></div>
                </div>     
                <!--操作按钮-->
                <div class="button_info clearfix">
                    <input type="button" value="保存"  id="save"class="btn_save"/>
                    <input type="button" value="取消" class="btn_save" onclick="location='list?shidcardNo=${shidcardNo }&shrealName=${shrealName }&shloginName=${shloginName}&shstatus=${shstatus}&page=${page}'"/>
                </div>
            </form>
        </div>
        
        <%@include file="../common/bottom.jsp"%>
    </body>
</html>
